package eoa;

public class DictionaryFactory {

	private static DictionaryFactory instance;

	public static synchronized DictionaryFactory getInstance() {
		if (instance == null) {
			instance = new DictionaryFactory();
		}
		return instance;
	}

	private DictionaryFactory() {

	}

	public void startTranslation(String word, String englishToDutch) {
		IDictionary id;
		switch (englishToDutch) {
		case "y":
			id = new KoenenAdapter(true);
			if (searchTranslation(id, word) == false) {
				id = new KramersAdapter();
				if (searchTranslation(id, word) == false) {
					System.out
							.println("The requested translation has not been found");
				}

			}
			break;
		case "n":
			id = new KoenenAdapter(false);
			searchTranslation(id, word);
			break;
		}

	}

	private boolean searchTranslation(IDictionary id, String word) {
		if (id.translate(word) != null) {
			System.out.println("\nThe requested translation has been found\n"
					+ "Source: " + id.getName() + "\nTranslation: "
					+ id.translate(word));
			return true;
		} else {
			return false;
		}
	}
}
